package link.wangkui;


import java.util.TimerTask;
import java.util.concurrent.*;

public class ScheduledDemo {
    public static void main(String[] args) {
        final TimerTask task1 = new TimerTask() {
            @Override
            public void run() {
                System.out.println("666");
                throw new RuntimeException();
            }
        };

        final TimerTask task2 = new TimerTask() {
            @Override
            public void run() {
                System.out.println("task2 invoked!");
            }
        };
        ScheduledExecutorService executorService = Executors.newScheduledThreadPool(10);
        executorService.schedule(task1, 100, TimeUnit.MILLISECONDS);
        executorService.scheduleAtFixedRate(task2, 0, 1000, TimeUnit.MILLISECONDS);
    }
}
